 <?php if($_SESSION['Permit']==1)
 { 
   
	$sqlMenus =sprintf("select * from tblmenu");
	$menusResult= mysql_query($sqlMenus) or die(mysql_error());
	$menuArray = array();
 	while($row = mysql_fetch_object($menusResult)){
		$menuArray[] = $row;
	}
 	$menuSortedArray = array();
	$countMenu = count($menuArray);
	for($i =0 ; $i< $countMenu; $i++){
		if($menuArray[$i]->parent_id ==0){
			$menuArray[$i]->vi_name = "-".$menuArray[$i]->vi_name;
			$menuSortedArray[] = $menuArray[$i];
			for($j =0 ; $j< $countMenu; $j++){
				if($menuArray[$j]->parent_id == $menuArray[$i]->id){
					$menuArray[$j]->vi_name = "----".$menuArray[$j]->vi_name;
					$menuSortedArray[] = $menuArray[$j];
					for($k =0 ; $k< $countMenu; $k++){
						if($menuArray[$k]->parent_id == $menuArray[$j]->id){
							$menuArray[$k]->vi_name = "------".$menuArray[$k]->vi_name;
							$menuSortedArray[] = $menuArray[$k];
						}
					}
				}
			}
		}
	}
	
 } 
 else
 { 
 	//xử lý sau

 }   

?>
  <script type="text/javascript">
  
  function Delete()
  {	  
  		var answer = confirm ("Bạn có chắc là muốn xóa những mục đã chọn?");
		if (answer)
		{
			document.mylist.submit();
		}
  }

  function checkAll(control)
	{
		field= document.getElementsByName('cid[]');
		if(control.checked)
{ 
		for (i = 0; i < field.length; i++)
		field[i].checked = true ;
	}

else

for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}




 </script>    
   

   <div align="center" style="padding:10 10 10 10; border:1px black solid;">
    <form name="mylist" action="menu/deletemenu.php" method="post"> 
  <table>
  	<tr>
    	<td colspan="4"><h3>Quản lý Menu</h3></td>
        <td colspan="2" align="right">
        	<a  href="menua" title="Thêm mới một menu" style="margin-right:15px;"><img src="img/Add.png" width="32" height="32" border="none"/></a>
        	<a  style="margin-right:15px;" title="Xóa mục đã chọn" onclick="Delete()"><img src="img/delete.png" width="32" height="32"/></a>
		   	
        </td>
    </tr>
    
    
  
    <tr bgcolor="#008000" style="color:white; height:30px;">
       <th width="5%" align="center"><input type="checkbox" name="toggle"  id="toggle" onclick=" checkAll(this);" /></th>
      <th width="25%" >Tên Tiếng Việt</th>
      <th width="25%" >Tên Tiếng Anh</th>
      <th width="20%" >URL  </th>
      <th width="10%" >Vị trí</th>
      <th width="10%">Đưa lên tab</th>
       
    </tr>
   
    <?php  $i=0;
	foreach($menuSortedArray as $row)
	{
	?>
     <tr  bgcolor="<?php if($i%2!=0) echo '#f6f8db';else echo  '#9ff1a1'?>" onmouseover="changeback(this);" onmouseout="changebre(this);">
    	  <td align="center"><input type="checkbox" name="cid[]" value="<?php echo $row->id?>" /></td>
         <td ><a href="menue&id=<?php echo $row->id?>"><?php echo $row->vi_name;?></a></td>
         <td ><a href="menue&id=<?php echo $row->id?>"><?php echo $row->en_name;?></a></td>
         <td ><?php echo $row->url; ?></td>
    	 <td ><?php echo $row->order; ?></td>
    	 <td><?php echo ($row->featured ==1) ? "Có" : "Không";?>
	
    <?php
    $i++;
	}
	?>
 
      
   </table>
   </form> 
</div>
